package com.grf.hadoop.flow_bean;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class FlowReducer extends Reducer<Text, FlowBean, Text, FlowBean> {


    private FlowBean v = new FlowBean();

    @Override
    protected void reduce(Text key, Iterable<FlowBean> values, Context context)
            throws IOException, InterruptedException {

        int sumUpFlow = 0;
        int sumDownFlow = 0;

        //累加求和
        for (FlowBean value : values) {
            sumUpFlow += value.getUpFlow();
            sumDownFlow += value.getDownFlow();
        }
        //v.setSumFlow(sumDownFlow + sumDownFlow);
        //写出

        v.set(sumUpFlow,sumUpFlow);
        context.write(key, v);
    }
}
